﻿using CPPEI.Coolzon.Configuration;
using CPPEI.Coolzon.Configuration.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace CPPEI.Coolzon.Theme.Fashion
{
    [XConfigRoot("Environment")]
    public class CZEnvironment
    {
        private static Version _version;
        /// <summary>
        /// 获得主程序的版本号
        /// </summary>
        public static Version Version
        {
            get
            {
                if (_version == null)
                {
                    _version = typeof(CZEnvironment).Assembly.GetName().Version;
                }
                return _version;
            }
        }

        /// <summary>
        /// 版本信息-.-.-
        /// </summary>
        public static string Version3
        {
            get
            {
                return Version.ToString(3);
            }
        }


        private static CZEnvironment s_instance;
        public static CZEnvironment Instance
        {
            get
            {
                if (s_instance == null)
                {
                    s_instance = new CZEnvironment();
                }
                return s_instance;
            }
        }

        /// <summary>
        /// 是否显示activex组件
        /// </summary>
        [XConfig("IsShowActiveXPart", false)]
        public bool IsShowActiveXPart { get; private set; }

        /// <summary>
        /// 是否自动创建控制域
        /// </summary>
        [XConfig("IsAutoCreateDomain", true)]
        public bool IsAutoCreateDomain { get; private set; }

        /// <summary>
        /// 登录模式
        /// </summary>
        [XConfig("LoginMode", "Windows")]
        public string LoginMode { get; private set; }

        /// <summary>
        /// 是否全屏显示
        /// </summary>
        [XConfig("IsFullScreen", true)]
        public bool IsFullScreen { get; private set; }

        /// <summary>
        /// 更新服务配置
        /// </summary>
        [XConfig("UpdateServiceConfig")]
        public ServiceConfig UpdateServiceConfig { get; private set; }

        #region static methods

        public static string GetHostConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.xml");
        }
        public static string GetSpareHostConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.spare.xml");
        }

        public static string GetPartLibConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\partlibs.xml");
        }

        /// <summary>
        /// 获取方案的存放目录地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionDirectoryPath(string solution)
        {
            return string.Format("{0}\\Coolzon\\ConsoleApp\\v{1}\\Solution\\{2}\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3,
                solution);
        }

        /// <summary>
        /// 获得方案的配置文件的地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionFilePath(string solution)
        {
            return string.Format("{0}\\Coolzon\\ConsoleApp\\v{1}\\Solution\\{2}\\{2}.xml", 
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3,
                solution);
        }

        /// <summary>
        /// 获取日志目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}\\Coolzon\\Logs\\v{1}\\ConsoleApp\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3);
        }

        /// <summary>
        /// 获得用户自己录制的按钮的配置信息文件路径
        /// </summary>
        /// <param name="userIdentity">用户编号</param>
        /// <param name="solutionName">方案名称</param>
        /// <param name="sceneName">场景名称</param>
        /// <returns></returns>
        public static string GetCustomActionFilePath(string userIdentity, string solutionName, string sceneName)
        {
            return string.Format("{0}\\Coolzon\\ConsoleApp\\v{1}\\CustomerData\\{2}\\{3}\\{4}.xml", 
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3,
                userIdentity,
                solutionName,
                sceneName);
        
        }

        /// <summary>
        /// 是否在场景打开之后默认显示按钮面板
        /// </summary>
        /// <returns></returns>
        public static bool IsShowActionPanelWhenOpenScene()
        {
            return true;
        }

        /// <summary>
        /// 获取Environment.xml文件的地址
        /// </summary>
        /// <returns></returns>
        public static string GetEnvironmentFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\Environment.xml"); ;
        }

        #endregion
    }
}
